home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWResour / Include / FWPrvRFl.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.0 KB  |  216 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:        FWPrvRFl.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPRVRFL_H
  11. #define FWPRVRFL_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. #ifndef FWFILESP_H
  18. #include "FWFileSp.h"
  19. #endif
  20.  
  21. #ifndef FWRESFI_K
  22. #include "FWResFil.k"
  23. #endif
  24.  
  25. #ifndef  FWCOUPTR_H
  26. #include "FWCouPtr.h"
  27. #endif
  28.  
  29. #ifndef FWPRIEXC_H
  30. #include "FWPriExc.h"
  31. #endif
  32.  
  33. #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
  34. #include <windows.h>
  35. #endif
  36.  
  37. #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
  38. #include <Types.h>
  39. #endif
  40.  
  41. #if FW_LIB_EXPORT_PRAGMAS
  42. #pragma lib_export on
  43. #endif
  44.  
  45. #if defined FW_BUILD_MAC
  46. typedef short FW_ResourceFileID;
  47. typedef Handle FW_ResourceHandle;
  48. #elif defined FW_BUILD_WIN
  49. typedef HINSTANCE FW_ResourceFileID;
  50. typedef HRSRC FW_ResourceHandle;
  51. #endif
  52.  
  53. //========================================================================================
  54. // Exception codes for resources
  55. //========================================================================================
  56.  
  57. const FW_PlatformError FW_xResourceFile                    = -30025;
  58. const FW_PlatformError FW_xResourceNotFound                = -30026;
  59. const FW_PlatformError FW_xResourceNotLoaded            = -30027;
  60. const FW_PlatformError FW_xResourceFileNotFound            = -30028;
  61.  
  62. //========================================================================================
  63. // CLASS FW_CPrivResourceFileRep
  64. //========================================================================================
  65. // This internal class is the reference counted representation class used by the
  66. // FW_CResourceFile class defined above.
  67.  
  68. class FW_CLASS_ATTR FW_CPrivResourceFileRep : public FW_CCountedPtrRep
  69. {
  70. public:
  71.     virtual ~ FW_CPrivResourceFileRep();
  72.         // Closes the underlying resource file if necessary.
  73.  
  74.     FW_CPrivResourceFileRep(const FW_CFileSpecification& newFileSpec);
  75.         // Open a resources file by name.
  76.         // This instance assumes responsibility for closing the file.
  77.  
  78.     FW_CPrivResourceFileRep(FW_ResourceFileID resFileID);
  79.         // Attach to a previously opened file.
  80.         // This instance does not assume responsibility for closing the file.
  81.  
  82.     const FW_CFileSpecification* GetFileSpecification() const;
  83.         // Get the file specificaiton for the resourcesFile.
  84.     
  85.     FW_Boolean HasResource(FW_ResourceId resourceId,
  86.                            FW_ResourceType resourceType) const;
  87.         // Returns TRUE if the resource exists in the file, FALSE if it doesn't.
  88.  
  89.     FW_ResourceHandle GetResourceHandle(FW_ResourceId resourceId,
  90.                                         FW_ResourceType resourceType) const;
  91.         // Gets the resource handle.  Resource data may still be purgeable or unloaded.
  92.         // Client assumes responsibility to call ReleaseResourceHandle when done.
  93.  
  94.     void ReleaseResourceHandle(FW_ResourceHandle handle) const;
  95.         // Releases the resource handle.  All memory is released.
  96.  
  97.     FW_Boolean PrivHasSpecialResource(FW_ResourceId resourceId,
  98.                                         FW_ResourceType resourceType) const;
  99.         // Returns TRUE if the resource exists in the file, FALSE if it doesn't.
  100.     
  101.     FW_PlatformHandle PrivGetSpecialResource(FW_ResourceId resourceId,
  102.                                                FW_ResourceType resourceType) const;
  103.         // Gets the special resource handle.
  104.         // It is the clients reponsibility to release the handle if necessary,
  105.         // using whatever platform specific code is required.
  106.  
  107.     FW_ResourceFileID    PrivGetResourceFileID();
  108.         // Return the platforms's "file ID" for this resources file.
  109.     
  110. protected:
  111.  
  112.     void ThrowExceptionIfResourceLoadError(
  113.                                         FW_PlatformHandle resourceHandle,
  114.                                         FW_ResourceId resourceId,
  115.                                         FW_ResourceType resourceType) const;
  116.         // The bottleneck from which resources exceptions are thrown.
  117.  
  118. private:
  119.  
  120.     FW_ResourceHandle GetResource(FW_ResourceId resourceId,
  121.                                    FW_ResourceType resourceType) const;
  122.         // Attempt to load the resource, return NULL if failed.
  123.     
  124.     static FW_CFileSpecification GetFileSpecificationForID(FW_ResourceFileID resFileID);
  125.         // Given a file ID, return the file spec for the file.
  126.  
  127.     static FW_ResourceFileID OpenResourceFile(const FW_CFileSpecification& fileSpec);
  128.         // Attempts to open the file, throws exceptions on failure.
  129.  
  130.     static void CloseResourceFile(FW_ResourceFileID file);
  131.         // Closes the file.
  132.         
  133.     FW_Boolean                fMustCloseFile;
  134.         // TRUE if this instance has assumed responsibility for closing the file.
  135.  
  136.     FW_ResourceFileID         fResourceFileID;
  137.         // The platform's file ID for the resources file.
  138.  
  139.     FW_CFileSpecification    fFileSpec;
  140.         // The file specificaiton for the resources file.
  141.  
  142. private:
  143.  
  144.     FW_CPrivResourceFileRep(const FW_CPrivResourceFileRep&);
  145.         // Don't allow copy construction
  146.         
  147.     FW_CPrivResourceFileRep& operator=(const FW_CPrivResourceFileRep&);
  148.         // Don't allow copy by value
  149.                  
  150. };
  151.  
  152. //----------------------------------------------------------------------------------------
  153. // FW_CPrivResourceFileRep::PrivGetResourceFileID()
  154. //----------------------------------------------------------------------------------------
  155.  
  156. inline FW_ResourceFileID FW_CPrivResourceFileRep::PrivGetResourceFileID()
  157. {
  158.     return fResourceFileID;
  159. }
  160.  
  161. //========================================================================================
  162. // CLASS FW_PPrivResourceFile
  163. //========================================================================================
  164.  
  165. class FW_CLASS_ATTR FW_PPrivResourceFile : public FW_CCountedPtr
  166. {
  167. public:
  168.     FW_PPrivResourceFile();
  169.         // Create a "NULL" FW_PPrivResourceFile
  170.         
  171.     FW_PPrivResourceFile(FW_CPrivResourceFileRep* privResourceFileRep);
  172.     FW_PPrivResourceFile(const FW_PPrivResourceFile& privResourceFile);
  173.     virtual ~ FW_PPrivResourceFile();
  174.         
  175.     FW_PPrivResourceFile& operator=(const FW_PPrivResourceFile& other);
  176.         // Assignment, point this pointer to the same rep as the other pointer points to.
  177.  
  178.     // ----- Overload of accessors methods -----
  179.     FW_CPrivResourceFileRep* operator->() const;
  180.     FW_CPrivResourceFileRep& operator*() const;    
  181. };
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // FW_PPrivResourceFile::operator=
  185. //----------------------------------------------------------------------------------------
  186.  
  187. inline FW_PPrivResourceFile& FW_PPrivResourceFile::operator=(const FW_PPrivResourceFile& other)
  188. {
  189.     SetRep(other.fRep);
  190.     return *this;
  191. }
  192.     
  193. //----------------------------------------------------------------------------------------
  194. // FW_PPrivResourceFile::operator->
  195. //----------------------------------------------------------------------------------------
  196.  
  197. inline FW_CPrivResourceFileRep* FW_PPrivResourceFile::operator->() const
  198. {
  199.     return (FW_CPrivResourceFileRep*)fRep;
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // FW_PPrivResourceFile::operator*
  204. //----------------------------------------------------------------------------------------
  205.  
  206. inline FW_CPrivResourceFileRep& FW_PPrivResourceFile::operator*() const
  207. {
  208.     return *((FW_CPrivResourceFileRep*)fRep);
  209. }
  210.  
  211. #if FW_LIB_EXPORT_PRAGMAS
  212. #pragma lib_export off
  213. #endif
  214.  
  215. #endif
  216.